package com.u.social.recommend.service.articles;

import com.u.social.recommend.model.ArticleDTO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: u-social
 * @description: 粗排
 * @author: Alex Wu
 * @createDate: 2025-04-07 17:19
 **/

@Service
public class RoughRankingService {



    /**
     * 粗排--根据权重规则进行排序
     * @param hotRecalls 热门召回
     * @param embeddingRecalls 嵌入召回
     * @param exploreRecalls 探索召回
     * @return 排序后的文章列表
     */
    public  List<ArticleDTO> roughSortByWeightRule(List<ArticleDTO> hotRecalls,
                                List<ArticleDTO> embeddingRecalls,
                                List<ArticleDTO> exploreRecalls) {
        for (ArticleDTO article : hotRecalls) {
            article.setScore(article.getScore() * 0.5f);
        }
        for (ArticleDTO article : embeddingRecalls) {
            article.setScore(article.getScore() * 0.3f);
        }
        for (ArticleDTO article : exploreRecalls) {
            article.setScore(article.getScore() * 0.2f);
        }
        List<ArticleDTO> allArticles = new ArrayList<>();
        allArticles.addAll(hotRecalls);
        allArticles.addAll(embeddingRecalls);
        allArticles.addAll(exploreRecalls);

        allArticles.sort((a1, a2) -> Float.compare(a2.getScore(), a1.getScore()));

        return allArticles.subList(0, Math.min(100, allArticles.size()));
    }


}
